package com.szholly.plug.form.excel.core.imp;

import java.util.List;

import com.szholly.plug.form.excel.model.TableEntity;

/**
 * 数据导入参数
 */
public abstract class ImpDataPar {

	protected String tableName;

	protected int colLength;

	protected List<String> arrColumn;

	protected TableEntity tableEntity;

	protected String userId;

	protected String dsName;

	protected static final String ERROR_DICT_INFO = "字典项错误；";
	protected static final String ERROR_REPEAT_INFO = "数据重复；";
	protected static final String ERROR_REQUIRED_INFO = "数据必填；";
	protected static final String ERROR_DATATYPE_INFO = "数据类型错误；";

	protected static final String CURRENT_DATE = "currentDate";
	protected static final String CURRENT_USER = "currentUser";

	public static final String INTEGER_TYPE = "int";
	public static final String STRING_TYPE = "string";
	public static final String DOUBLE_TYPE = "double";
	public static final String DATE_TYPE = "date";
	public static final String DATETIME_TYPE = "datetime";

	public static final String TEMP_TABEL_SUFFIX = "_temp";

	public ImpDataPar(TableEntity tableEntity, String userId, String dsName) {
		this.tableName = tableEntity.getName();
		this.arrColumn = tableEntity.getColumnName();
		this.tableEntity = tableEntity;
		this.colLength = arrColumn.size();
		this.userId = userId;
		this.dsName = dsName;
	}

	/**
	 * 获取列字符串 例如列名,列名,列名 用于查询和插入数据
	 * 
	 * @return
	 */
	public StringBuilder getStrColName() {
		StringBuilder sbColName = new StringBuilder();
		for (int i = 0; i < colLength; i++) {
			if (i < colLength - 1) {
				sbColName.append(arrColumn.get(i) + ",");
			}
			if (i == colLength - 1) {
				sbColName.append(arrColumn.get(i));
			}
		}
		return sbColName;
	}

	/**
	 * 获取列参数 例如?,?,? 用于插入数据
	 * 
	 * @return
	 */
	public StringBuilder getStrParam() {
		StringBuilder sbColParam = new StringBuilder();
		for (int i = 0; i < colLength; i++) {
			if (i < colLength - 1) {
				sbColParam.append("?,");
			}
			if (i == colLength - 1) {
				sbColParam.append("?)");
			}
		}
		return sbColParam;
	}
}
